package org.example.cloudnativelab.controller;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.example.cloudnativelab.annotation.Limiting;
import org.example.cloudnativelab.entity.Message;
import org.example.cloudnativelab.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {
    @Autowired
    private MessageService messageService;

    private final Timer httpRequestsTimer;

    @Autowired
    public MessageController(MeterRegistry meterRegistry) {
        this.httpRequestsTimer = meterRegistry.timer("http_requests_duration", "uri", "/msg");
    }

    @Limiting(limitNum = 100)
    @GetMapping("/msg")
    public Object getMessage() {
        return messageService.getMessage();
    }
}
